#!/bin/bash
FILEWITHEXT="$1"
FILEBASENAME="${FILEWITHEXT##*/}"
FNAME="${FILEBASENAME%.*}"

if [ "x${1}" == "x" ]
then
  echo "no file given, use as $0 file_to_convert.mkv"
  exit 2
fi

if [ "x${1}" == "x${FNAME}.mkv" ]
then
  echo "writing to same file?"
  FNAME="${FNAME}_new"
fi

if [ -f "${FNAME}.mkv" ]
then
  echo "file already encoded"
  exit 3
fi
echo $FNAME
ffmpeg -y -i "$1" -map 0:a:0 -map 0:v:0 \
  -acodec libaacplus -ac 2 -ab 64k -ar 48k \
  -vcodec libx264 -x264opts "force-cfr:chroma-qp-offset=2" -async 2 \
  -sn -preset:v slower \
  "$FNAME.mkv"
